package com.arvato.wxwork.controller.front.ncc;

import java.util.Date;
import java.util.List;
import java.util.Map;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import com.arvato.minipro.bean.bean_dto.common.PageData;
import com.arvato.minipro.bean.bean_dto.common.Query;
import com.arvato.minipro.bean.bean_dto.common.Result;
import com.arvato.wxwork.bean.bean_do.ncc.WxworkGreetDo;
import com.arvato.wxwork.bean.bean_vo.ncc.WxworkGreetVo;
import com.arvato.wxwork.service.ncc.WxworkGreetService;

/**
 * 资生堂NCC(客户关怀) 处理BC需发送任务相关逻辑的Controller
 * @author ZHAN655
 */
@RestController
@RequestMapping("/wxwork/ncc/greet")
public class WxworkNccGreetController{
	
	private Logger logger = LoggerFactory.getLogger(WxworkNccGreetController.class);
	
	@Autowired
	private WxworkGreetService wxworkGreetService; 
	
	@ResponseBody
	@RequestMapping(value="/list")
	public PageData listGreet(@RequestParam Map<String, Object> param) {
		logger.info("调用greet Query接口");
		Query query =new Query(param);
		List<WxworkGreetVo> greet = wxworkGreetService.listGreetByQuery(query);
		PageData pageData = new PageData(Long.valueOf(greet.size()), greet);
		return pageData;
	}
	
	@ResponseBody
	@RequestMapping(value="/insert")
	public Result insertGreet(WxworkGreetDo greetDo) {
		logger.info("调用insertGreet接口");
		greetDo.setCreateTime(new Date());
		greetDo.setType(0);
		greetDo.setEditable(0);
		int row=wxworkGreetService.insert(greetDo);
		String id = greetDo.getId();
		if(row == 1) {
			return Result.success(id);
		}
		return Result.fail("操作失败");
	}
	
	/**
	 * 获取一个问候语的详情
	 * @param id
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value="/detail")
	public Result GreetDetail(String id) {
		WxworkGreetVo greetVo = wxworkGreetService.getGreetById(id);
		return Result.success(greetVo);
	}
	
}
